package com.windgo.controller.admin;

import com.windgo.bean.bo.OrderCommentReplyBo;
import com.windgo.bean.bo.OrderDeleteBo;
import com.windgo.bean.bo.OrderRefundBo;
import com.windgo.bean.bo.OrderShipVo;
import com.windgo.bean.MarketOrder;
import com.windgo.bean.vo.OrderChannel;
import com.windgo.bean.vo.OrderDetailVo;
import com.windgo.bean.common.BasePageInfo;
import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.common.CommonData;
import com.windgo.service.OrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author:ZhouXin
 * @Date:2022/10/13 11:32
 * @Description:
 **/
@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;


    /**
     * 订单管理中，显示订单信息
     * @param info
     * @param userId
     * @param orderSn
     * @param orderStatusArray
     * @param start
     * @param end
     * @return
     */
    @RequiresPermissions("perms[admin:order:list]")
    @GetMapping("list")
    public BaseRespVo list(BasePageInfo info, Integer userId, String orderSn, Short[] orderStatusArray, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end){
        CommonData<MarketOrder> data=orderService.list(info,userId,orderSn,orderStatusArray,start,end);
        return BaseRespVo.ok(data);
    }

    /**
     * 订单详情
     * @param id
     * @return
     */
    @GetMapping("detail")
    public BaseRespVo detail(Integer id){
        OrderDetailVo data=orderService.detail(id);
        return BaseRespVo.ok(data);
    }

    /**
     * 显示快递公司
     * @return
     */
    @GetMapping("channel")
    public BaseRespVo channel(){
        List<OrderChannel> data=new ArrayList<>();
        OrderChannel channel = new OrderChannel("ZTO","中通快递");
        data.add(channel);
        OrderChannel channel1 = new OrderChannel("TD","圆通速递");
        data.add(channel1);
        OrderChannel channel2 = new OrderChannel("YD","韵达速递");
        data.add(channel2);
        OrderChannel channel3 = new OrderChannel("YZPY","邮政包裹");
        data.add(channel3);
        OrderChannel channel4 = new OrderChannel("EMS","EMS");
        data.add(channel4);
        OrderChannel channel5 = new OrderChannel("DBL","德邦快递");
        data.add(channel5);
        return BaseRespVo.ok(data);
    }

    /**
     * 根据编号删除订单
     * @param orderDeleteBo
     * @return
     */
    @PostMapping("delete")
    @RequiresPermissions("perms[admin:order:delete]")
    public BaseRespVo delete(@RequestBody OrderDeleteBo orderDeleteBo){
        Integer orderId = orderDeleteBo.getOrderId();
        orderService.delete(orderId);
        return BaseRespVo.ok();
    }


    /**
     * 发货，增加快递公司和快递单号
     * @return
     */
    @PostMapping("ship")
    @RequiresPermissions("perms[admin:order:ship]")
    public BaseRespVo ship(@RequestBody OrderShipVo orderShipVo){
        orderService.ship(orderShipVo);
        return BaseRespVo.ok();
    }

    /**
     * 退款
     * @param orderRefundBo
     * @return
     */
    @PostMapping("refund")
    @RequiresPermissions("perms[admin:order:refund]")
    public BaseRespVo refund(@RequestBody OrderRefundBo orderRefundBo){
        orderService.refund(orderRefundBo);
        return BaseRespVo.ok();
    }


    /**
     * 回复商品评论
     * @param orderCommentReplyBo
     * @return
     */
    @PostMapping("reply")
    @RequiresPermissions("perms[admin:order:reply]")
    public BaseRespVo reply(@RequestBody OrderCommentReplyBo orderCommentReplyBo){
        orderService.reply(orderCommentReplyBo);
        return BaseRespVo.ok(662,"订单商品已回复");
    }

}
